import logging
from flask_script import Manager
from flask_migrate import Migrate,MigrateCommand
from info import create_app,db
from info.models import User
from setting import DevelopmentConfig
from info import models

# 调用create_app函数，返回app
app = create_app(DevelopmentConfig)
# 数据库迁移配置
manager = Manager(app)
# manager.create_app(app)
Migrate(app,db)
manager.add_command('bigNB', MigrateCommand)

# 创建管理员账户指令
@manager.option('-u', dest = 'name')
@manager.option('-p', dest = 'password')
def createsuperuser(name, password):
    if not all([name, password]):
        print('参数不足')

    user = User()
    user.nick_name = name
    user.mobile = name
    user.password = password
    user.is_admin = True
    try:
        db.session.add(user)
        db.session.commit()
    except Exception as e:
        print('创建失败')

    print('创建成功')


if __name__ == '__main__':
    # logging.debug("'I'm Debug")
    # print(app.url_map)
    manager.run()